<template>
  <div class="mailBox">
    <div class="mailContent">
      <div class="logo">
        <img src="../../assets/images/logo2.png" alt="图片" />
        <span>磐石致维</span>
      </div>
      <div class="iconText">
        <svg class="iconfont" aria-hidden="true">
          <use :xlink:href="`#el-icon-my${resList.icon}`" style="font-size: 50px" />
        </svg>
        <div>{{ resList.iconTip }}</div>
        <div class="tip">{{ resList.tip }}</div>
        <el-button class="btnSizeStyle" type="primary" @click="toLogin">去登录</el-button>
      </div>
    </div>
    <div class="footer">Copyright © 2020-{{ year }} 湖南同恒信息技术有限公司 版权所有.</div>
  </div>
</template>
<script>
import { timestampToTime } from '@/assets/js/setTime'
import { pinT } from '@/utils/allUrl.js'
export default {
  data() {
    return {
      year: '',
      list: [
        {
          // 验证失败 错号
          icon: 'problem',
          iconTip: '验证失败',
          tip: '邮箱验证失败,请登录后重新验证',
        },
        {
          // 验证成功 对号
          icon: 'yanzhengchengg',
          iconTip: '验证成功',
          tip: '5s 后将自动跳到登录页面',
        },
        {
          // 链接失败 感叹号
          icon: 'lianjieshixiao',
          iconTip: '链接失效',
          tip: '你访问的页面已失效，请登录后重新验证',
        },
      ],
      resList: {
        icon: '',
        iconTip: '',
        tip: '',
      },
      timer: null,
    }
  },
  created() {
    this.year = timestampToTime().year
    clearInterval(this.timer)
    this.verificationEmail()
  },
  methods: {
    async verificationEmail() {
      // 获取地址栏参数
      let token = ''
      if (JSON.stringify(this.$route.query) !== '{}') {
        token = this.$route.query.token
      }
      const params = new URLSearchParams()
      params.append('token', token)
      const { data: res } = await this.$http.post(`${pinT}yonghu/verificationEmail`, params)
      switch (res.code) {
        case '0000':
          this.resList = this.list[1]
          var num = 5
          this.timer = setInterval(() => {
            if (num === 0) {
              clearInterval(this.timer)
              this.toLogin()
              return
            }
            num--
            this.resList.tip = `${num}s 后将自动跳到登录页面`
          }, 1000)
          break
        case '0010': // 连接失效
          this.resList = this.list[2]
          break
        case '0001': // 连接失效
          this.resList = {
            icon: 'problem',
            iconTip: '验证失败',
            tip: res.message,
          }
          break
        default:
          // 失败
          this.resList = this.list[0]
          break
      }
    },
    toLogin() {
      this.$router.push('/login')
    },
  },
  destroyed() {
    clearInterval(this.timer)
  },
}
</script>
<style lang="scss" scoped>
.mailBox {
  .mailContent {
    background-color: #fff;
    padding: 0 50px;
    padding-top: 20px;
    .logo {
      display: table;
      img,
      span {
        display: table-cell;
        vertical-align: middle;
        line-height: 30px;
      }
      img {
        height: 30px;
      }
      span {
        color: #5d5d5d;
        font-size: 24px;
        padding-left: 10px;
      }
    }
    .iconText {
      margin: 0 auto;
      text-align: center;
      font-size: 14px;
      line-height: 30px;
      color: #434343;
      padding: 200px 90px;
      .iconfont {
        width: 47px;
        height: 47px;
      }
      .tip {
        color: #9f9f9f;
        padding-bottom: 120px;
        border-bottom: 1px solid #e7e7eb;
      }
      .el-button {
        padding: 0 30px;
        margin-top: 30px;
      }
    }
  }
  .footer {
    color: #999999;
    font-size: 12px;
    padding: 30px 0;
    text-align: center;
  }
}
</style>
